package testJdk.anno.newer;

import org.junit.Test;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;

/**
 * @version 1.0.0
 * Created by cyd on 2024-07-29 16:16:07
 * @ClassName : testJdk.anno.newer.Test
 * @Description : 类描述
 */
public class TestDemo {

    @Test
    public void test() throws Exception {
        Class<MyAnnoAccess> aClass = MyAnnoAccess.class;
        System.out.println("-------类上的注解-------");
        Annotation[] declaredAnnotations = aClass.getDeclaredAnnotations();
        for (Annotation declaredAnnotation : declaredAnnotations) {
            System.out.println(declaredAnnotation);
        }
        System.out.println("-------字段上的注解-------");
        Field field = aClass.getDeclaredField("some");
        System.out.println(field);
        Annotation[] annotations = field.getDeclaredAnnotations();
        for (Annotation annotation : annotations) {
            System.out.println(annotation);
        }
        System.out.println("-------构造器上的注解-------");
        Constructor<MyAnnoAccess> constructor = aClass.getConstructor(String.class);
        if (constructor.isAnnotationPresent(ConstructorAnnotation.class)){
            ConstructorAnnotation annotation = constructor.getAnnotation(ConstructorAnnotation.class);
            System.out.println(annotation);
            System.out.println(annotation.value());
        }

    }
}
